package com.yiwenup.leetcode.top_interview_150;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.top_interview_150
 * @Author yiwenup
 * @Date 2024-12-17 21:35:34
 * @Description https://leetcode.cn/problems/reverse-string-ii/
 */
public class No0541 {
    public String reverseStr(String s, int k) {
        char[] ans = s.toCharArray();

        for (int i = 0; i < s.length(); i += 2 * k) {
            int left = i;
            int right = Math.min(i + k, s.length()) - 1;
            while (left < right) {
                char tmp = ans[left];
                ans[left] = ans[right];
                ans[right] = tmp;

                left++;
                right--;
            }
        }

        return new String(ans);
    }
}
